
  <template>
  <div class="bf-commont-template padding-t">
    <!-- 参数设置 -->
    <el-tabs :tab-position="'left'" v-model="activeName" @tab-click="handleClick" class="margin-l margin-r">
      <el-tab-pane label="招聘渠道" name="first">
        <div class="clearfix bf-top-button">
          <div class="float-l">
            <el-button type="primary" @click="showTypeAdd">新增招聘渠道</el-button>
          </div>
          <div class="float-r">
            <div class="float-l">
              <el-input placeholder="请输入名称搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch">
              </el-input>
            </div>
            <div class="float-l padding-l">
            </div>
          </div>
        </div>
        <bf-table
          :data="recruitTypeData"
          :setting="recruitTypeSetting"
          :rowAction="rowAction1"
          @editSubmit="recruitTypeEditSubmit"
          @pageChange="pageChange1"
          ref="table1"
        ></bf-table>
      </el-tab-pane>
      <el-tab-pane label="面试题库" name="second">
        <div class="clearfix bf-top-button">
          <div class="float-l">
            <el-button type="primary" @click="showInterviewAdd">新增面试题库</el-button>
          </div>
          <div class="float-r">
            <div class="float-l">
              <el-input placeholder="请输入题库类型搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch">
              </el-input>
            </div>
            <div class="float-l padding-l">
            </div>
          </div>
        </div>
        <bf-table
          :data="interviewProblemData"
          :setting="interviewProblemSetting"
          :rowAction="rowAction2"
          @editSubmit="interviewProblemEditSubmit"
          @pageChange="pageChange2"
          ref="table2"></bf-table>
      </el-tab-pane>
      <el-tab-pane label="淘汰原因" name="third">
        <div class="clearfix bf-top-button">
          <div class="float-l">
            <el-button type="primary" @click="showObsoletAdd">新增淘汰原因</el-button>
          </div>
          <div class="float-r">
            <div class="float-l">
              <el-input placeholder="请输入淘汰原因搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch">
              </el-input>
            </div>
            <div class="float-l padding-l">
              <!-- <el-button type="primary" @click="showSearch">高级筛选</el-button> -->
            </div>
          </div>
        </div>
        <bf-table
          :data="obsoleteData"
          :setting="obsoleteSetting"
          :rowAction="rowAction3"
          @editSubmit="obsoleteEditSubmit"
          @pageChange="pageChange3"
          ref="table3"
        ></bf-table>
      </el-tab-pane>
    </el-tabs>
    <!-- 添加 -->
    <bf-table-add :editForm='recruitTypeAddSetting' ref='recruitTypeRef' @formSubmit='addRecruitTypeSubmit' :editRules="addRules"></bf-table-add>
    <!-- 添加 -->
    <bf-table-add :editForm='interviewProblemAddSetting' ref='interviewProblemRef' @formSubmit='addInterviewProblemSubmit' :editRules="addRules"></bf-table-add>
    <!-- 添加 -->
    <bf-table-add :editForm='obsoleteAddSetting' ref='obsoleteRef' @formSubmit='addObsoleteSubmit' :editRules="addRules"></bf-table-add>

    <!--编辑 -->
    <bf-table-edit :editForm='recruitTypeSetting' ref='editRecruitTypeRef' @formSubmit='editRecruitTypeSubmit' :editRules="addRules"></bf-table-edit>
    <!-- 编辑-->
    <bf-table-edit :editForm='interviewProblemSetting' ref='editInterviewProblemRef' @formSubmit='editInterviewProblemSubmit' :editRules="addRules"></bf-table-edit>
    <!-- 编辑 -->
    <bf-table-edit :editForm='obsoleteSetting' ref='editObsoleteRef' @formSubmit='editObsoleteSubmit' :editRules="addRules"></bf-table-edit>
  </div>
</template>

<script>
/** @
 * addParameterChannel,新增渠道
 * addParameterQuestion,新增题库
 * addParameterEliminate ,新增淘汰原因
 */
import {
  getRecruitType,
  getInterviewProblem,
  getObsolete,
  addParameter,
  editParameter,
  deleteParameter
} from './api.js'
import { recruitTypeSetting, interviewProblemSetting, obsoleteSetting, recruitTypeAddSetting, interviewProblemAddSetting, obsoleteAddSetting } from './table.setting.js'

export default {
  data() {
    return {
      searchData: '',
      activeName: 'first',
      recruitTypeData: {},
      interviewProblemData: {},
      obsoleteData: {},
      recruitTypeSetting: recruitTypeSetting,
      interviewProblemSetting: interviewProblemSetting,
      obsoleteSetting: obsoleteSetting,
      recruitTypeAddSetting: recruitTypeAddSetting,
      interviewProblemAddSetting: interviewProblemAddSetting,
      obsoleteAddSetting: obsoleteAddSetting,
      userData: {
      },
      rowAction1: [
        {
          label: '查看',
          click: (item) => {
            this.$refs.table1.showDetail(item)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.$refs.editRecruitTypeRef.show(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table1.showDelete(item)
          }
        }
      ],
      rowAction2: [
        {
          label: '查看',
          click: (item) => {
            this.$refs.table2.showDetail(item)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.$refs.editInterviewProblemRef.show(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table2.showDelete(item)
          }
        }
      ],
      rowAction3: [
        {
          label: '查看',
          click: (item) => {
            this.$refs.table3.showDetail(item)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.$refs.editObsoleteRef.show(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table3.showDelete(item)
          }
        }
      ],
      setting: [
        {
          field: 'name',
          title: '用户名称',
          type: 'text',
          searchable: true
        },
        {
          field: 'roleName',
          title: '用户角色',
          type: 'text',
          searchable: true
        },
        {
          field: 'introduction',
          title: '用户介绍',
          type: 'text'
        },
        {
          field: 'avatar',
          title: '用户连接',
          type: 'text'
        }
      ],
      addRules: {
        recruittype: [
          { required: true, message: '请输入名称', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20个字符', trigger: 'blur' }
        ],
        itemText: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      },
      searchParams: { // 搜索条件
        page: 1
      }
    }
  },
  mounted: function() {
    this.searchList()
  },
  methods: {
    hidden() {
      this.$refs.recruitTypeRef.hidden()
      this.$refs.interviewProblemRef.hidden()
      this.$refs.obsoleteRef.hidden()
    },
    addRecruitTypeSubmit(form) { // 新增渠道
      const param = {
        paramCode: 'RECRUITMENTCHANNEL',
      }
      const obj = Object.assign(form, param)
      addParameter(obj).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.recruitTypeRef.hiden()
          this.hidden()
          this.searchList()
        }
      })
    },

    addInterviewProblemSubmit(form) { // 新增题库
      const param = {
        paramCode: 'INTERVIEWPROBLEM',
      }
      const obj = Object.assign(form, param)
      addParameter(obj).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchList()
          this.hidden()
        }
      })
    },
    addObsoleteSubmit(form) { // 新增淘汰原因
      const param = {
        paramCode: 'ELIMINATEREASON',
      }
      const obj = Object.assign(form, param)
      addParameter(obj).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.searchList()
          this.hidden()
        }
      })
    },

    editRecruitTypeSubmit(form) { // 编辑保存渠道
      editParameter(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.editRecruitTypeRef.hiden()
          this.searchList()
        }
      })
    },
    editInterviewProblemSubmit(form) { // 编辑保存题库
      editParameter(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.editInterviewProblemRef.hiden()
          this.searchList()
        }
      })
    },
    editObsoleteSubmit(form) { // 编辑保存淘汰原因
      editParameter(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.editObsoleteRef.hiden()
          this.searchList()
        }
      })
    },

    getRecruitType(pageParams) {
      getRecruitType(pageParams).then(response => {
        this.recruitTypeData = response
      })
    },
    getInterviewProblem(pageParams) {
      getInterviewProblem(pageParams).then(response => {
        this.interviewProblemData = response
      })
    },
    getObsolete(pageParams) {
      getObsolete(pageParams).then(response => {
        this.obsoleteData = response
      })
    },

    recruitTypeEditSubmit(params, formType, formList) { // 删除
      if (formType === 'delete') {
        const obj = params.row
        deleteParameter(obj).then(response => {
          if (response.success) {
            this.$message({
              message: '删除成功!',
              type: 'success'
            })
            this.searchList()
          }
        })
      }
    },

    interviewProblemEditSubmit(params, formType, formList) { // 删除
      if (formType === 'delete') {
        const obj = params.row
        deleteParameter(obj).then(response => {
          if (response.success) {
            this.$message({
              message: '删除成功!',
              type: 'success'
            })
            this.searchList()
          }
        })
      }
    },

    obsoleteEditSubmit(params, formType, formList) { // 删除
      if (formType === 'delete') {
        const obj = params.row
        deleteParameter(obj).then(response => {
          if (response.success) {
            this.$message({
              message: '删除成功!',
              type: 'success'
            })
            this.searchList()
          }
        })
      }
    },
    pageChange1(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },
    pageChange2(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },
    pageChange3(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },
    showSearch() {
      this.$refs.table.showSearch()
    },

    showTypeAdd() {
      this.activeName = 'first'
      this.$refs.recruitTypeRef.show()
    },
    showInterviewAdd() {
      this.activeName = 'second'
      this.$refs.interviewProblemRef.show()
    },
    showObsoletAdd() {
      this.activeName = 'third'
      this.$refs.obsoleteRef.show()
    },
    quickSearch() {
      this.searchParams.itemText = this.searchData
      this.searchList()
    },
    handleClick(tab, event) {
      this.searchParams.itemText = null
      this.searchList()
    },
    searchList() {
      const params = this.searchParams
      if (this.activeName === 'first') {
        params.paramCode = 'RECRUITMENTCHANNEL'
        this.getRecruitType(params)
        return false
      }
      if (this.activeName === 'second') {
        params.paramCode = 'INTERVIEWPROBLEM'
        this.getInterviewProblem(params)
        return false
      }
      if (this.activeName === 'third') {
        params.paramCode = 'ELIMINATEREASON'
        this.getObsolete(params)
        return false
      }
    }
  }
}
</script>

<style scoped>

</style>
